package day01;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author 你的名称
 * @createTime 30 17:07
 * @description
 */
public class testHelloworld {
    @Test
    public void testHelloworld(){
        Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-jdbc-realm.ini");
        SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken("chu","1234");
        try{
            subject.login(token);
        }catch (UnknownAccountException exception){
            System.out.println("账号有误!!!");
        }catch (IncorrectCredentialsException exception){
            System.out.println("密码有误!!!");
        }
        Assert.assertEquals(true,subject.isAuthenticated());
        subject.logout();
    }
}